#include "Base.h"
#include "GameProtocol.h"
#include "GameSvrPlayer.h"
#include "GameBot.h"
#include "BotServer.h"

CGameSvrPlayer::CGameSvrPlayer(void)
{
}

CGameSvrPlayer::~CGameSvrPlayer(void)
{
}

Msg* CGameSvrPlayer::CreateMsg(DWORD dwMsgId, int nLen)
{
	if(dwMsgId == Msg_SB_CallBotUser)
	{
		return new SBCallBotUserMsg;
	}
    return NULL;
}

BOOL CGameSvrPlayer::OnMsg(Msg *pMsg)
{
	DWORD dwMsgId = pMsg->GetMsgId();
	if(dwMsgId == Msg_SB_CallBotUser)
	{
		OnCallBotUser(pMsg);
	}
	return TRUE;
}

BOOL CGameSvrPlayer::OnCallBotUser(Msg *pMsg)
{
    SBCallBotUserMsg *pCallBotUser = (SBCallBotUserMsg *)pMsg;

	CGameBot *pGameBot = ((CBotServer*)g_pServer)->CreateGameBot();
	if(pGameBot == NULL)
	{
		WriteLog("%s : %d CreateGameBot return NULL", __FILE__, __LINE__);
		return TRUE;
	}
	pGameBot->m_dwProductId = pCallBotUser->m_dwProductId;
	pGameBot->m_dwMatchId = pCallBotUser->m_dwMatchId;
	pGameBot->m_dwUserId = pCallBotUser->m_dwUserId;

	char *szServerIP = inet_ntoa(GetClient()->GetClientAddr().sin_addr);
	int nPort = ((CBotServer*)g_pServer)->m_nGameSvrPort;
	pGameBot->OnInitialUpdate(szServerIP, nPort);
	return TRUE;
}